package com.neusoft.neuiotms.dcam.workflow.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.neuiotms.dcam.workflow.dto.ITSMApproveDTO;
import com.neusoft.neuiotms.dcam.workflow.dto.TuikuKJDTO;
import com.neusoft.neuiotms.dcam.workflow.service.TuikuKJService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "科技公司退库工单")
@RestController
@RequestMapping(value = "/api/w/workflow/tuikukj")
public class TuikuKJController {

    @Autowired
    private TuikuKJService tuikuKJService;

    @ApiOperation("新增物资退库申请")
    @PostMapping
    public ResultDTO<TuikuKJDTO> create(@RequestBody final TuikuKJDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.tuikuKJService.create(dto, user));
    }

    @ApiOperation("查看物资退库申请")
    @GetMapping("/{workOrderNum}/{taskId}")
    public ResultDTO<TuikuKJDTO> details(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.tuikuKJService.detail(workOrderNum, taskId, user));
    }

    @ApiOperation("ITSM审批")
    @PostMapping("itsm")
    public ResultDTO<ITSMApproveDTO> itsmCreate(@RequestBody final ITSMApproveDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.tuikuKJService.itsmCreate(dto, user));
    }

    @ApiOperation("查看ITSM审批")
    @GetMapping("itsm/{workOrderNum}/{taskId}")
    public ResultDTO<ITSMApproveDTO> itsmDetails(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.tuikuKJService.itsmDetails(workOrderNum, taskId, user));
    }

    @ApiOperation("新增物资退库确认")
    @PostMapping("confirm")
    public ResultDTO<Void> confirmCreate(@RequestBody final TuikuKJDTO dto,
            final UserBean user) {
        this.tuikuKJService.confrimCreate(dto, user);
        return ResultDTO.success();
    }

    @ApiOperation("查看物资退库确认")
    @GetMapping("confirm/{workOrderNum}/{taskId}")
    public ResultDTO<TuikuKJDTO> confirmDetails(@PathVariable final String workOrderNum,
            @PathVariable final String taskId,
            final UserBean user) {
        return ResultDTO.success(this.tuikuKJService.confrimDetail(workOrderNum, taskId, user));
    }
}
